<?php

namespace app\api\controller;

use app\common\controller\Api;
use \app\common\model;

/**
 * 私有云
 */
class Privatecloud extends Api
{
    protected $noNeedLogin = ['index'];
    protected $noNeedRight = [''];

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * @ApiTitle    (私有云)
     * @ApiAuthor   (Zhenzh)
     * @ApiDate     (2020/1/15)
     * @ApiSummary  (描述)
     * @ApiBody     (Body)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/privateCloud/index)
     * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码 1正常 0错误", sample="1")
     * @ApiParams         (name="code", type="string", required=true, description="授权码", sample="")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回", sample="")
     * @ApiReturn ()
     */
    public function index()
    {
        $code = $this->request->request('code');

        if (!$code) {
            $this->error('code 不能为空');
        }
        $ret = model\PrivateCloud::where('code', $code)->find();
        if (!$ret) {
            $this->error('code 错误');
        }
        if ($ret->logo) {
            if (!strstr($ret->logo, 'http') && strstr($ret->logo, '/uploads/')) {
                $ret->logo = config('app_url') . $ret->logo;
            }
        }
        $this->success('', $ret);
    }

}
